
version 13.1

//figure 1
use fpa-aid_bits_final,clear
keep if oecd_i==1&oecd_j==0
bys year: egen g_maid=total(commitment_amount_usd_constant_s) if commitment_amount_usd_constant_s!=.
gen g_lnmaid=ln(g_maid) if g_maid!=.
su g_lnmaid
grstyle init
grstyle set plain, nogrid noextend
twoway (line g_lnmaid year,ytitle("OECD aid (ln)")) ///
(line t_bit year, lcol(gs6)yaxis(2)ytitle("Annual No. of BITs in force", axis(2))ylabel(0 (300) 2400, axis(2))), xtitle(Year) legend(label(1 "Aid") label(2 "BITs")) xsize(4) ysize(3)

graph export f1.pdf, replace

//figure 2 
use fpa-aid_bits_final,clear
keep if oecd_i==1&oecd_j==0
grstyle init
grstyle set plain, nogrid noextend
twoway (kdensity lnaid if bit_ratf==1&lnaid!=0, col(gs4)) (kdensity lnaid if bit_ratf==0&lnaid!=0, color(gs12)), ///
legend (label(1 "BITs") label(2 "No BITs")) xtitle("Aid (ln)") xsize(5) ytitle("Kdensity")

graph export f2-b.pdf, replace

//figure 3
clear
set obs 2
gen id=_n
su id
gen coef=9.24
replace coef=5.34 if id==1
replace coef=9.24 if id==1
replace coef=5.34 if id==2
gen lower=5.34-1.96*0.026
gen higher =5.34+1.96*0.026
replace lower=9.24-1.96*0.147
replace lower=5.34-1.96*0.026 if id==2
replace higher=9.24+1.96*0.147 if id==1
rename coef ate
save bits_aid_ate, replace
grstyle init
grstyle set plain, nogrid noextend
set obs 3
replace id=0.8 in 3
twoway (rspike lower higher id, col(gs12))(scatter ate id, msymbol(sh)xlabel(1"BITs" 2"No BITs") xsc(r(1 2))), xsize(4)legend(off)xtitle("") ///
ytitle (Effects on foreign aid) 

graph export bit-aid-f3.pdf,replace

//figure 4
use fpa-bitsaid-figure4,clear

grstyle init
grstyle set plain, nogrid noextend
set obs 5
replace x=0.8 in 5
twoway (rspike lower higher x if x<=2)(scatter ate x if x<=2,msymbol(Sh))(line ate x if x<=2, xlabel(1"short" 2"long") xsc(r(1 2))), xsize(4)legend(off)xtitle(Time horizon) ///
ytitle (Average treatment effects) title(Democracies) 
graph save bit-aid-f4a.gph, replace
twoway (rspike lower higher x if x>2)(scatter ate x if x>2,msymbol(Sh))(line ate x if x>2, xlabel(3"short" 4"long") xsc(r(2.8 3 4))), xsize(4)legend(off)xtitle(Time horizon)  title(Non-Democracies) 
graph save bit-aid-f4b.gph, replace
graph combine bit-aid-f4a.gph bit-aid-f4b.gph

graph export bit-aid-f4.pdf, replace


//figure 5
use fpa-aid_bits_final, clear
sort dyad year
keep if oecd_i==1&oecd_j==0
quietly xtivreg2 lnaid l.p_polity2  l.ln_gdppc l.wdi_gdpgr l.wdi_fdiin l.wdi_natrr l.gdpgr_i l.pta l.unsc_member l.ally l.coldwar (lbit_ratf = l.t_bit) , fe first savefirst cluster(dyad)
predict res, e
gen yhat=lnaid-res
gen aid=exp(yhat)
grstyle init
grstyle set plain, nogrid noextend
set more off
stripplot yhat, cumul cumprob box centre mcolor(gs13) over(bit_ratf) refline vertical xsize(3)ytitle(Predicted aid (ln)) xtitle(BITs) 
graph export f5.pdf, replace

//figure 6
///democracies
clear
set obs 30
range office_yr 1 30
gen mv=13.5+office_yr*0.37
gen mv_se=sqrt(1.9^2+office_yr^2*0.13^2+2*office_yr*(1.9*0.13*0.8))
gen ub_mv=mv+1.96*mv_se
gen lb_mv=mv-1.96*mv_se
grstyle init
grstyle set plain, nogrid noextend
twoway (line mv office_yr,lp(solid)) (line ub office_yr,lp(dash)) (line lb office_yr,lp(dot)lcol(black)), ///
legend(off) xtitle(Executive years in office) ytitle(Marginal effect of BITs on foreign aid) title(Democracies)
graph save f6-a.gph,replace

///non-democracies
//
clear
set obs 46
range office_yr 1 46
gen mv=37.6+office_yr*(-0.23)
gen mv_se=sqrt(11.2^2+office_yr^2*0.17^2+2*office_yr*(11.2*0.17*0.75))
gen ub_mv=mv+1.96*mv_se
gen lb_mv=mv-1.96*mv_se
grstyle init
grstyle set plain, nogrid noextend
gen yline=0
twoway (line mv office_yr,lp(solid)) (line ub office_yr,lp(dash)lcol()) (line lb office_yr,lp(dot)lcol(black)) (line yline office_yr,lp(solid)lcol(gs10)lwidth(thin)), ///
legend(off) xtitle(Executive years in office) ytitle(Marginal effect of BITs on foreign aid) title(Non-Democracies)
graph save f6-b.gph,replace

graph combine f6-a.gph f6-b.gph

graph export f6.pdf, replace

log close
